package me.myqaq.myqaqcraft.slimefunaddon.supper;

import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem;
import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack;
import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;

public class axe_god extends SlimefunItem {

    public axe_god(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
        super(itemGroup, item, recipeType, recipe);
    }
    @Override
    public void preRegister() {
        ItemUseHandler itemUseHandler=this::onItemUseRightClick;
        addItemHandler(itemUseHandler);
    }
    private void onItemUseRightClick(PlayerRightClickEvent event) {
        // 如果在这里调用 event.cancel() 会阻止玩家手持物品默认右键事件
        event.cancel();
        int ello =  event.getPlayer().getLevel();
        if ( ello>=30){
            event.getPlayer().giveExpLevels(-30);
            if (event.getClickedBlock().isPresent()){
                    Block b = event.getClickedBlock().get();
                    World w =b.getWorld();
                    Location loc=b.getLocation();
                    w.strikeLightning(loc);
                    event.getPlayer().sendMessage("§c我tm来拉~~");
                }
        }else{
            event.getPlayer().sendMessage("§4he~呸！30级经验都没有！死~杂~鱼~");
            event.getPlayer().giveExpLevels(-2);
            event.getPlayer().setHealth(1);
        }

    }
}
